package _26define;

import java.io.*;

public class Test {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        serialize();

        unSerialize();

    }
    private static void unSerialize() throws IOException, ClassNotFoundException {
        ObjectInputStream in=new ObjectInputStream(new FileInputStream("src/note/a.txt"));
        Object o=in.readObject();
        System.out.println(o);
        in.close();
    }
    private static void serialize() throws IOException {
        Student student = new Student("ls", 21,59);
        // 创建输出流对象
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("src/note/a.txt"));
        // writeObject(Object o)
        out.writeObject(student);
        // close
        out.close();
    }
}
class Student implements Serializable{
    String name;
    int age;
    transient int score;

    static final long serialVersionUID=-7889256375299507710L;
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Student(String name, int age, int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }
}
